--Api 表
/*
select * from SYS_Apis
select * from SYS_ApiM --M  Memo Main Manage
ReturnType
返回类型（类似返回值）
1 execSql 
2 openSql
3 execProc(不带返回结果) 
4 openProc(带返回结果集)
5 getList (使用getList sql 模板)
6 执行updata,delete 等，返回 操作的行数
*/

declare 
  @ApiName varchar(50)='sjdg.fjList',
  @ReturnType int =5
--
--
delete from SYS_Apis where apiName=@ApiName
delete from SYS_ApiM where apiName=@ApiName
insert into SYS_ApiM
  ([apiName],[Name],Memo)
select @ApiName,'底稿列表','底稿列表 在复核平台中使用，Api接口中使用'
insert into SYS_Apis(ApiName,paramsLen,params,ReturnType,sqlText)
select @ApiName,0,
'',
@ReturnType,
'select a.linkID,isnull(a.pLinkID,'''') as pLinkID,a.linkType, 
  case when a.linkType=0 then linkDGID else cast(b.fjName+b.fjlx as nvarchar(100)) end linkText,
  case when a.linkType=0 then ''..'' else cast(b.fjlx as varchar(10)) end lx,
  b.fjsyh,b.userName,b.addDate,cast(b.fjid as nvarchar(100))fjid 
  from [#(dbname)]..dglinkinfo a left join [#(dbname)]..sjdg_fj b on  a.LinkDGID=b.fjid 
  where isnull(a.IsDel,0)=0 and a.LinkType in(0,2) and (a.LinkType=0 or isnull(b.fjName,'''')<>'''')
  and a.dgid=#para(dgid)
order by b.fjsyh,b.fjname,linkText' 